<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style>
  .box{
    margin: 0 auto;
    width: 330px;
    height: 330px;
    background: red;
  }
  .box > div{
    float: left;
    width: 100px;
    height: 100px;
    background: skyblue;
    margin: 5px;
  }
</style>
<body>
      <div class="box">
      </div>
</body>
<script>
class PLayer{
  PLayer1 = 'o'
  PLayer2 = 'x'
  flag=1
  set1(){
    let myflag=this.flag
    let arr=document.querySelector('.box').querySelectorAll('div')
    for (let i =0;i<arr.length;i++){
      arr[i].addEventListener('click',function(){
        if( arr[i].style.background=='yellow' ||  arr[i].style.background=='green'){
          return;
        }
        else if(myflag  == 1){
          arr[i].style.background='yellow'
          myflag = 2
          console.log( arr[i].style.background)
        }
        else if(myflag  == 2){
          arr[i].style.background= 'green'
          myflag= 1;
        }
      })
    }
    this.flag=myflag
    // div.addEventListener('click',function(a){
    //         console.log(a)
    //       })
}
}
class Board{
    constructor(n) {
        //棋盘数组 
        this.n=n;
    }
    isFull(){
        //判断棋牌是否满了
    }
    check_win(){
        //判断谁赢了
    }
    generateHTMLBoard(){
        //根据棋盘数组生成棋盘的 HTML
        for(let i =0;i<this.n;i++){
          let div = document.createElement('div')
          document.querySelector('.box').appendChild(div)
        }
    }
}
let board = new Board(9)
board.generateHTMLBoard()
let player = new PLayer()

for(let i =0;i<9;i++){
  player.set1()
}
</script>
</html>